/**
 * Created on Oct 12, 2011
 */
package com.pason.onlineshop.mainshop.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;




import com.pason.onlineshop.mainshop.annotation.QueryField;
import com.pason.onlineshop.mainshop.controller.form.OrderDTO;
import com.pason.onlineshop.mainshop.service.entity.query.impl.QueryParameter.QueryOperateType;

/**
 * @author Pason Hu
 *
 */
@Entity
@Table(name = "shoporder")
@NamedQueries({
	@NamedQuery(name="Order.listOrders",
			    query="select c from Order c"), 
	@NamedQuery(name="Order.findById", 
			    query="select distinct c from Order c where c.id = :id")
})

public class Order implements Serializable {

	private Long id;
	
	@QueryField(webName="totalPrice", queryType=QueryOperateType.Equal)
	private String totalPrice;
	
	@QueryField(webName="orderTitle", queryType=QueryOperateType.CharIn)
	private String orderTitle;
	
	private Date createDate;

	public Order() {
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "ID")
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "TOTAL_PRICE")
	public String getTotalPrice() {
		return this.totalPrice;
	}

	public void setTotalPrice(String totalPrice) {
		this.totalPrice = totalPrice;
	}

	@Column(name = "ORDER_TITLE")
	public String getOrderTitle() {
		return this.orderTitle;
	}

	public void setOrderTitle(String orderTitle) {
		this.orderTitle = orderTitle;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "CREATE_DATE")
	public Date getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}	
	
	public String toString() {		
		return "Order - Id: " + id + ", Order Title: " + orderTitle 
				+ ", Total Price: " + totalPrice + ", Create date: " + createDate;
	}	
	
	public static Order fromDTO(OrderDTO orderDTO) {
		Order order = new Order();
		order.setOrderTitle(orderDTO.getOrderTitle());
		order.setTotalPrice(orderDTO.getTotalPrice());
		return order;
	}

}
